/**
 * 
 */
package com.risetek.tft.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.risetek.tft.service.LogsService;
import com.zlinepay.framework.bean.AjaxJson;
import com.zlinepay.framework.bean.DwzModel;
 

/**
 */
@Controller
@RequestMapping(value = "/logs")
public class LogsAction extends BaseAction {

	@RequestMapping(value = "/list")
	@ResponseBody
	public DwzModel list(DwzModel dataGrid ,  HttpServletRequest request, ModelMap model)
			throws Exception {
		String hql = "select new map(a.id as id,date_format(a.optime,'%Y-%m-%d %H:%i'),a.title as title,a.account as account,a.message as message,a.url as url,a.ip as ip) FROM TLogs a";
		if(StringUtils.isNotEmpty(dataGrid.getOrderField())) {
			hql += " order by a."+dataGrid.getOrderField()+" "+dataGrid.getOrderDirection();
		}
		return logsService.pagedQuery(hql.toString(),"select count(*) from TLogs t    ",   dataGrid);
	}
	
	@RequestMapping(value = "/remove.action")
	@ResponseBody
	public AjaxJson del(Integer[] ids, HttpServletRequest request,
			HttpServletResponse response, ModelMap model) {
		AjaxJson json = new AjaxJson();
		try {
			logsService.delete(ids);
			json.setSuccess(true);
			json.setMsg("删除成功！");
		} catch (Exception e) {
			e.printStackTrace();
			json.setMsg("删除失败！");
		}
		return json;
	}

	@Autowired
	private LogsService logsService;
	
}
